<template>
	<view class="inform">
		<text class="defaultText" v-if="!groupList.length > 0">暂时没有新的通知</text>
		<view class="" v-else style="display: flex;justify-content: space-between;align-items: center;margin-top: 10px;padding-bottom: 5px;border-bottom: #DEDEDE solid 1px;" v-for="(item,index) in groupList">
			<view class="" style="display: flex;align-items: center;margin-left: 15px;"  v-if="item.status==1?false:true">
				<image :src="item.avatar" mode="" style="width: 50px;height: 50px;border-radius: 50px;"></image>
				<view style="margin-left: 15px;">{{item.squser}}</view>
			</view>
			<view class="" style="display: flex;margin-right: 15px;">
				<view style="margin-right: 10px;padding: 5px;" @click="toty(item.qid,item.squser)">同意</view>
				<view style="padding: 5px;" @click="tojj(item.qid,item.squser)">拒绝</view>
			</view>
		</view>
	</view>
</template>

<script>
	let WebIM = require("../../utils/WebIM")["default"];
	let disp = require("../../utils/broadcast");
	export default {
		data() {
			return {
				groupList: [],
				array:'',
				name:''
			}
		},
		onLoad(options) {
			this.name = options.myName
		},
		onShow() {
			this.token = uni.getStorageSync("token")
			this.arrays();
			
			// console.log(this.array)
			
		},
		methods: {
			arrays(){
				// console.log(this.array)
				uni.request({
					url: this.G_base + '/api/lz/qzmsg',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + this.token
					},
					data: {
						account:this.name
					},
					success: res => {
						
							this.groupList=res.data.data
							console.log(this.groupList)
					}
				})
			},
			toty(id,nickname){
				let arr = []
				arr.push(nickname)
				let option = {
				    users: arr,
				    groupId: id
				};
				console.log(option)
				WebIM.conn.inviteToGroup(option).then((res) => {
				    console.log(res)
					uni.request({
						url: this.G_base + '/api/lz/sqjqr',
						data:{
							id:id,
							account:nickname,
							status:1
						},
						method: "POST",
						header: {
							'content-type': 'application/x-www-form-urlencoded',
							'Authori-zation': 'Bearer ' + this.token
						},
						success: (res) => {
							console.log(res);
							if(res.data.status == 200){
								uni.showToast({
									title:res.data.msg,
									icon:'none'
								})
								setTimeout(function(){
									uni.navigateBack({
										delta:1
									})
								},2000)
							}else{
								uni.showToast({
									title:res.data.msg,
									icon:'none'
								})
							}
						},
					});
				})

				
			},
			tojj(id,nickname){
				// console.log(id)
				// console.log(nickname)
				uni.request({
					url: this.G_base + '/api/lz/sqjqr',
					data:{
						id:id,
						account:nickname,
						status:2
					},
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation': 'Bearer ' + this.token
					},
					success: (res) => {
						console.log(res);
						if(res.data.status == 200){
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
							setTimeout(function(){
								uni.navigateBack({
									delta:1
								})
							},2000)
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					},
				});
			}
		}
	}
</script>

<style scoped>
	*{
		font-size: 17px;
	}
	page {
		background-color: #FAFAFA;
	}

	.defaultText {
		color: #E3E3E3;
		font-size: 32rpx;
		text-align: center;
		display: block;
		margin: 300rpx auto 0 auto;
	}

	.itemBar {
		margin: 20rpx 40rpx;
		min-height: 252rpx;
		background-color: #fff;
		border: 1px solid #FAFAFA;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.notInfoDetContent {
		min-height: 160rpx;
		width: 100%;
		border-bottom: 1px solid #FAFAFA;
	}

	.headContent {
		width: 72rpx;
		height: 72rpx;
		border-radius: 50%;
		margin: 24rpx 30rpx 0;
		float: left;
	}

	.headContent image {
		width: 72rpx;
		height: 72rpx;
	}

	.infoContent {
		display: flex;
		flex-direction: column;
	}

	.infoContent text {
		min-height: 54rpx;
		line-height: 54rpx;
		font-size: 28rpx;
		color: #9B9B9B;
	}

	.infoContent .itemName {
		height: 62rpx;
		font-size: 32rpx;
		line-height: 62rpx;
		color: #000;
		margin-top: 24rpx;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.buttonContent {
		display: inline-flex;
		width: 100%;
		flex: 1;
		height: 72rpx;
	}

	.buttonContent .agreeBtn,
	.buttonContent .rejectBtn {
		flex: 1;
		font-size: 32rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.agreeBtn {
		color: #0873DE;
	}

	.rejectBtn {
		color: #666666;
	}

	.centerLine {
		border-right: 1px solid #FAFAFA;
	}

	.actionDone {
		flex: 1;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #999999;
	}
</style>
